import { HttpError, toSuccess, useEntityManager } from "@sker/core"
import { AutoUser } from '@sker/entities'
import { useData } from '@sker/runtime'
import { z } from 'zod'
export default async () => {
    const input = z.object({
        masterMinTime: z.number(),
        masterMaxTime: z.number(),
        uuid: z.string(),
        token: z.string(),
        masterMaxCount: z.number(),
        status: z.string(),
        minMoneyV: z.optional(z.number()),
        hours: z.optional(z.any())
    })
    const body = input.parse(useData())
    await useEntityManager(async m => {
        const user = await m.findOne(AutoUser, { where: { token: body.token } })
        if (!user) {
            throw new HttpError(`登陆失效`)
        }
        await m.update(AutoUser, user.id, { setting: { hours: body.hours || [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], minMoneyV: body.minMoneyV || 0.9, minTime: body.masterMinTime, status: body.status, maxTime: body.masterMaxTime, maxCount: body.masterMaxCount } as any })
    })
    return toSuccess(true)
}